package com.mdd.controller;

import com.mdd.common.CustomException;
import com.mdd.common.R;
import com.mdd.pojo.vo.SalesTopVo;
import com.mdd.service.TopService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController("/top")
public class TopController {

    @Autowired
    private TopService topService;

    /**
     * 获取菜品或者销量排行榜(0为菜品你销量榜，1为套餐销量榜)
     * @return
     */
    @GetMapping("/sales/{type}")
    public R<SalesTopVo> getSalesTop(@PathVariable("type") Integer type){
        if (type == null) {
            throw new CustomException("请求参数为空");
        }
         SalesTopVo salesTopVo = topService.getSalesTop(type);
        return R.success(salesTopVo);
    }
}
